//
//  MTDiscoverFriendSearchBar.swift
//  MT
//
//  Created by ooops on 2020/5/5.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

protocol MTSearchFriendListHeaderViewDelegate: NSObjectProtocol {
    /// 点击搜索
    func didTapSearchFriendButton()
    
}

class MTSearchFriendListHeaderView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
    }
    
    weak var delegate: MTSearchFriendListHeaderViewDelegate?
    
    lazy var searchButton: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "search-bar"), for: .normal)
        btn.addTarget(self, action: #selector(searchFriend), for: .touchUpInside)
        btn.setTitleColor(UIColor.text.x1d1a1a, for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(14)
        btn.contentHorizontalAlignment = .left
        //btn.sizeToFit()
        //btn.imageRect(forContentRect: CGRect(x: 0, y: 0, width: 44, height: 54))
        return btn
    }()
    
    private func setupUI() {
        addSubview(searchButton)
    }
    
    private func makeConstraint() {
        searchButton.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview()
//            make.bottom.right.equalToSuperview().offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    func setSearchTitlt(title: String) {
        searchButton.setTitle(" 搜索: " + title, for: .normal)
    }
    
    @objc private func searchFriend() {
        
        self.delegate?.didTapSearchFriendButton()
        
    }
    

}
